package demo1;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.net.URL;

/**
 * @Author liangzai
 * @Description:
 */
public class Demo extends JFrame {
    public JTextField jTextField;
    public JPasswordField jTextField1;


    public void inti(String title, int wight, int hight){
//        //底部按钮（安全登录）
//        //JLabel label = new JLabel("hello world");
//        URL url1 = this.getClass().getClassLoader().getResource("image/image/image/login.png");
//        JButton button = new JButton(new ImageIcon(url1));
//        button.setBorder(BorderFactory.createRaisedBevelBorder());
//
//        button.setBorderPainted(false);
//        button.setContentAreaFilled(false);
//        //button.setBackground(Color.cyan);
//        //button .setFont(new  java.awt.Font("华文行楷",  1,  15));
//        //button.setPreferredSize(new Dimension(300,40));
//        //this.add(label, BorderLayout.NORTH);
//        //button.addActionListener(this);
//        this.add(button,BorderLayout.SOUTH);




        //右侧按钮（正方形菜单）
        JPanel jp = new JPanel();
        URL url2 = this.getClass().getClassLoader().getResource("image/image/image/ercode.png");
        JButton button1 = new JButton(new ImageIcon(url2));
        button1.setBorderPainted(false);
        button1.setContentAreaFilled(false);
        //BorderLayout borderLayout = new BorderLayout();
        jp.setLayout(null);
        jp.add(button1);
        button1.setBounds(370,-5,50,50);
        //this.add(jp);
        this.add(jp,BorderLayout.WEST);




        //右侧按钮（注册账号）
        //JPanel jp1 = new JPanel();
        //JButton button2 = new JButton("注册账号");
        JLabel jLabel6 = new JLabel("注册账号");
        jp.setLayout(null);
//        button2.setBorderPainted(false);
//        button2.setContentAreaFilled(false);
        jp.add(jLabel6);
        //JLabel.setBounds(-42, -10, 150, 50);
        //this.add(jp);
        this.add(jp,BorderLayout.EAST);



        URL url = this.getClass().getClassLoader().getResource("image/image/image/head.png");
        JLabel label1 = new JLabel(new ImageIcon(url));



        //JTextField jTextField = new JTextField();

        //this.add(jTextField,BorderLayout.CENTER);

        this.add(label1,BorderLayout.NORTH);


        JPanel center_jp = new JPanel(new GridLayout(3,3));
        //1 1
        JLabel jLabel = new JLabel("qq号码");
        jTextField = new JTextField();
        URL url3 = this.getClass().getClassLoader().getResource("image/image/image/clear.gif");
        JButton button3 = new JButton(new ImageIcon(url3));
        button3.setBorderPainted(false);
        button3.setContentAreaFilled(false);
        center_jp.add(jLabel);
        center_jp.add(jTextField);
        center_jp.add(button3);

        //2,2
        JLabel jLabel1 = new JLabel("qq密码");
        jTextField1 = new JPasswordField();
        JButton button4 = new JButton("忘记密码");
        button4.setBorderPainted(false);
        button4.setContentAreaFilled(false);
        center_jp.add(jLabel1);
        center_jp.add(jTextField1);
        center_jp.add(button4);

        //3 3
        JLabel jLabel2 = new JLabel("隐身登录");
        JLabel jLabel3 = new JLabel("记住密码");
        JLabel jLabel4 = new JLabel("申请密码保护");
        jLabel4.setForeground(Color.blue);
        center_jp.add(jLabel2);
        center_jp.add(jLabel3);
        center_jp.add(jLabel4);

        this.getContentPane().setLayout(new FlowLayout());
        //this.getContentPane().add(jp);
        this.add(center_jp,BorderLayout.CENTER);

//底部按钮（安全登录）
        //JLabel label = new JLabel("hello world");
        URL url1 = this.getClass().getClassLoader().getResource("image/image/image/login.png");
        JButton button = new JButton(new ImageIcon(url1));
        button.setBorder(BorderFactory.createRaisedBevelBorder());

        button.setBorderPainted(false);
        button.setContentAreaFilled(false);
        this.add(button,BorderLayout.SOUTH);

        this.setTitle(title);

        this.setSize(wight,hight);

        this.setVisible(true);

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.setLocationRelativeTo(null);
    }

    public void actionPerformed(ActiveEvent e){
        System.out.println("按钮被点击了！");
        String qq = jTextField.getText().toString().trim();
        String pwd = jTextField1.getText().toString().trim();
        if("123456".equals(qq) && "admin".equals(pwd)){
            System.out.println("登陆成功！");
            this.dispose();
            Chat chat = new Chat();
            chat.init("qq聊天",400,600);
            new Thread(){
                public void run(){
                    chat.connServer();
                }
            }.start();
        }else{
            JOptionPane.showMessageDialog(this,"用户名或密码错误！");
        }

    }
}
